package com.controller;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.service.ScoreService;
import com.service.StudentService;

@RestController
@RequestMapping("/login")
public class LoginController {

	@Resource
	private StudentService studentService;
	@Resource
	private ScoreService scoreService;
	
	@RequestMapping("/check")
	public Map loginAction(HttpServletRequest request, Model model) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
		// 从index.jsp的表单获取到的用户输入的姓名 xm
		String studentName = request.getParameter("studentName");
		// //从index.jsp的表单获取到的用户输入的学号 xh
		String studentNumber = request.getParameter("studentNumber");
		// 从数据库查询到的用户密码
		String xm = this.studentService.getStudentNameById(studentNumber);
		String message = "";
		// 判断姓名是否一致
		Map<String, Object> result = new HashMap<>();
		if (studentName.equals(xm)) {
			result.put("code", 0);
			return result;
		}
		result.put("code", 400);
		return result;
	}
	
	
	
	
}
